<template>
  <div class="app-container">
    <el-row :gutter="20">

      <!--部门数据-->
      <el-col :span="4" :xs="24">
        <el-card class="box-card">
          <div slot="header" class="clearfix">
            <span>区域代理列表</span>
          </div>
          <div class="head-container">
            <el-input placeholder="输入关键字进行过滤" size="small" v-model="filterText" clearable>
            </el-input>
            <el-tree :data="proxyOptions" :props="defaultProps" :expand-on-click-node="false"
              :filter-node-method="filterNode" ref="tree" default-expand-all @node-click="handleNodeClick" />
          </div>
        </el-card>

      </el-col>
      <!--订单数据-->
      <el-col :span="20" :xs="24">
        <el-card class="box-card">
          <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
            <el-form-item label="订单编号" prop="num">
              <el-input v-model="queryParams.num" placeholder="请输入订单编号" clearable size="small"
                @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="订单分类" prop="categoryName">
              <el-input v-model="queryParams.categoryName" placeholder="请输入订单分类" clearable size="small"
                @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="订单信息" prop="attribute">
              <el-input v-model="queryParams.attribute" placeholder="请输入订单信息" clearable size="small"
                @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="规格属性" prop="tags">
              <el-input v-model="queryParams.tags" placeholder="请输入规格属性" clearable size="small"
                @keyup.enter.native="handleQuery" />
            </el-form-item>

            <el-form-item label="预约时间">
              <el-date-picker v-model="daterangeOrderTime" size="small" style="width: 240px" value-format="yyyy-MM-dd"
                type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
            </el-form-item>

            <el-form-item label="联系人" prop="username">
              <el-input v-model="queryParams.username" placeholder="请输入联系人姓名" clearable size="small"
                @keyup.enter.native="handleQuery" />
            </el-form-item>
            <!-- <el-form-item label="联系电话" prop="telephone">
              <el-input
                v-model="queryParams.telephone"
                placeholder="请输入联系人电话"
                clearable
                size="small"
                @keyup.enter.native="handleQuery"
              />
            </el-form-item> -->

            <el-form-item label="接单人" prop="receiveName">
              <el-input v-model="queryParams.receiveName" placeholder="请输入接单人姓名" clearable size="small"
                @keyup.enter.native="handleQuery" />
            </el-form-item>

            <el-form-item label="分享人" prop="shareUser">
              <el-input v-model="queryParams.shareUser" placeholder="请输入账号" clearable size="small"
                @keyup.enter.native="handleQuery" />
            </el-form-item>

            <el-form-item label="经理" prop="jingli">
              <el-input v-model="queryParams.jingli" placeholder="请输入经理账号" clearable size="small"
                @keyup.enter.native="handleQuery" />
            </el-form-item>

            <!-- <el-form-item label="接单电话" prop="receivePhone">
              <el-input
                v-model="queryParams.receivePhone"
                placeholder="请输入接单人电话"
                clearable
                size="small"
                @keyup.enter.native="handleQuery"
              />
            </el-form-item> -->
            <!--
            <el-form-item label="状态" prop="status">
              <el-select v-model="queryParams.status" placeholder="请选择状态" clearable size="small">
                <el-option label="全部" value="" />
                <el-option
                  v-for="dict in statusOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                ></el-option>
              </el-select>

            </el-form-item> -->

            <el-form-item>
              <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
              <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
          </el-form>

          <el-tabs v-model="tabActiveName" @tab-click="handleTabClick">
            <el-tab-pane label="全部" name="all"></el-tab-pane>
            <el-tab-pane v-for="dict in statusOptions" :key="dict.dictValue" :label="dict.dictLabel"
              :name="dict.dictValue"></el-tab-pane>
          </el-tabs>
          <el-table v-loading="loading" :data="orderList" @selection-change="handleSelectionChange">
            <el-table-column type="expand" width="55" align="center">
              <template slot-scope="scope">
                <el-row :gutter="20">
                  <el-col :span="8">
                    <el-card class="box-card">
                      <el-tabs>
                        <el-tab-pane label="服务地址">
                          <el-form label-width="80px">
                            <el-row :gutter="20">
                              <el-col :span="12">
                                <el-form-item label="用户" prop="userName" style="margin-bottom: 8px;">
                                  {{ scope.row.orderAddress.userName }}
                                </el-form-item>
                              </el-col>
                              <el-col :span="12">
                                <el-form-item label="电话" prop="userTelephone" style="margin-bottom: 8px;">
                                  {{ scope.row.orderAddress.userTelephone }}
                                </el-form-item>
                              </el-col>
                            </el-row>
                            <el-row :gutter="20">
                              <el-col :span="24">
                                <el-form-item label="详细地址" prop="detail" style="margin-bottom: 8px;">
                                  {{ scope.row.orderAddress.area }}{{ scope.row.orderAddress.detail }}
                                </el-form-item>
                              </el-col>
                            </el-row>
                          </el-form>
                        </el-tab-pane>
                      </el-tabs>
                    </el-card>
                  </el-col>
                  <el-col :span="16">
                    <el-card class="box-card">
                      <el-tabs>
                        <el-tab-pane label="支付记录">
                          <el-table v-loading="loading" :data="scope.row.paymentList">
                            <el-table-column label="支付金额" align="center" prop="amount" />
                            <el-table-column label="支付方式" align="center" prop="payWay" />
                            <el-table-column label="交易流水号" align="center" prop="transNo"
                              :show-overflow-tooltip="true" />
                            <el-table-column label="类型" align="center" prop="payType" :formatter="formatPaytype" />
                            <el-table-column label="主题" align="center" prop="subject" :show-overflow-tooltip="true" />
                            <el-table-column label="内容" align="center" prop="body" show-overflow-tooltip />
                            <el-table-column label="支付状态" align="center" prop="status">
                              <template slot-scope="scope">
                                <el-tag v-if="scope.row.status == 1" type="success" size="mini">已支付</el-tag>
                                <el-tag v-else type="danger" size="mini">未支付</el-tag>
                              </template>
                            </el-table-column>
                            <el-table-column label="支付时间" align="center" prop="successTime" width="180">
                              <template slot-scope="scope">
                                <span>{{ parseTime(scope.row.successTime) }}</span>
                              </template>
                            </el-table-column>

                          </el-table>
                        </el-tab-pane>

                        <el-tab-pane label="抢单记录">
                          <el-table v-loading="loading" :data="scope.row.receiveList">
                            <el-table-column label="抢单人" align="center" prop="userName" />
                            <el-table-column label="联系电话" align="center" prop="userTelephone" />
                            <el-table-column label="抢单时间" align="center" prop="createTime" width="180">
                              <template slot-scope="scope">
                                <span>{{ parseTime(scope.row.createTime) }}</span>
                              </template>
                            </el-table-column>
                            <el-table-column label="备注" align="center" prop="remark" />
                            <el-table-column label="状态" align="center" prop="status">
                              <template slot-scope="scope">
                                <el-tag v-if="scope.row.status == 1" type="success" size="mini">已确认</el-tag>
                                <el-tag v-else type="danger" size="mini">未确认</el-tag>
                              </template>
                            </el-table-column>
                          </el-table>
                        </el-tab-pane>
                        <el-tab-pane label="检查记录">
                          <el-table v-loading="loading" :data="scope.row.checkList">
                            <el-table-column label="地址" align="center" prop="address" />
                            <el-table-column label="图片" align="center" prop="imgUrl">
                              <template slot-scope="scope">
                                <el-image v-if="scope.row.imgUrl" style="width: 100px; height: auto"
                                  :src="scope.row.imgUrl" :preview-src-list="[scope.row.imgUrl]">
                                </el-image>
                              </template>
                            </el-table-column>
                            <el-table-column label="结论" align="center" prop="remark" :formatter="resultFomat" />
                            <el-table-column label="检查时间" align="center" prop="createTime" width="180">
                              <template slot-scope="scope">
                                <span>{{ parseTime(scope.row.createTime) }}</span>
                              </template>
                            </el-table-column>
                          </el-table>
                        </el-tab-pane>
                        <el-tab-pane label="服务记录">
                          <el-table v-loading="loading" :data="scope.row.serviceList">
                            <el-table-column label="服务人员" align="center" prop="receiveName" />
                            <el-table-column label="服务开始时间" align="center" prop="beginTime" width="180">
                              <template slot-scope="scope">
                                <span>{{ parseTime(scope.row.beginTime) }}</span>
                              </template>
                            </el-table-column>
                            <el-table-column label="服务结束时间" align="center" prop="endTime" width="180">
                              <template slot-scope="scope">
                                <span>{{ parseTime(scope.row.endTime) }}</span>
                              </template>
                            </el-table-column>
                            <el-table-column label="图片" align="center" prop="imgUrl">
                              <template slot-scope="scope">
                                <el-image v-if="scope.row.imgUrl" style="width: 100px; height: auto"
                                  :src="scope.row.imgUrl" :preview-src-list="[scope.row.imgUrl]">
                                </el-image>
                              </template>
                            </el-table-column>
                            <el-table-column label="备注" align="center" prop="remark" />
                          </el-table>
                        </el-tab-pane>
                        <el-tab-pane label="评价记录">
                          <el-table :data="form.commentList">
                            <el-table-column label="类型" align="center" prop="type">
                              <template slot-scope="scope">
                                <div v-if="scope.row.type == 1">用户评价</div>
                                <div v-if="scope.row.type == 2">服务方评价</div>
                              </template>
                            </el-table-column>
                            <el-table-column label="评分" align="center" prop="score" />
                            <el-table-column label="内容" align="center" prop="content" />
                            <el-table-column label="评论者" align="center" prop="createUserName" />
                            <!-- <el-table-column label="被评论者" align="center" prop="commentedUserName" /> -->
                            <el-table-column label="图片" align="center" prop="imgUrl">
                              <template slot-scope="scope">
                                <el-image v-if="scope.row.imgUrl" style="width: 100px; height: auto"
                                  :src="scope.row.imgUrl" :preview-src-list="[scope.row.imgUrl]">
                                </el-image>
                              </template>
                            </el-table-column>
                          </el-table>
                        </el-tab-pane>
                      </el-tabs>

                    </el-card>

                  </el-col>
                </el-row>

              </template>
            </el-table-column>
            <el-table-column label="订单编号" align="center" width="170" prop="num">
              <template slot-scope="scope">
                <el-button type="text" @click="handleShow(scope.row)">{{ scope.row.num }}</el-button>
              </template>
            </el-table-column>
            <el-table-column label="订单分类" align="left" prop="categoryName" />
            <el-table-column label="订单信息" align="left" prop="attribute" show-overflow-tooltip width="150" />
            <!-- <el-table-column label="规格属性" align="center" prop="tags" show-overflow-tooltip /> -->
            <el-table-column label="预约时间" align="center" prop="orderTime" width="150">
              <template slot-scope="scope">
                <span>{{ parseTime(scope.row.orderTime) }}</span>
              </template>
            </el-table-column>
            <el-table-column label="区域" align="center" prop="district" width="100" />
            <!-- <el-table-column label="服务地址" align="left" prop="address" width="220" /> -->
            <el-table-column label="下单人" align="left" prop="username" width="120">
              <template slot-scope="scope">
                <div>{{ scope.row.username }}</div>
                <div>{{ scope.row.telephone }}</div>
              </template>
            </el-table-column>
            <!-- <el-table-column label="联系电话" align="center" prop="telephone" /> -->
            <el-table-column label="接单人" align="left" prop="receiveName" width="120">
              <template slot-scope="scope">
                <div>{{ scope.row.receiveName }}</div>
                <div>{{ scope.row.receivePhone }}</div>
              </template>
            </el-table-column>
            <!-- <el-table-column label="联系人" align="center" prop="username" />
            <el-table-column label="联系电话" align="center" prop="telephone" width="110"/>
            <el-table-column label="接单人" align="center" prop="receiveName" />
            <el-table-column label="接单电话" align="center" prop="receivePhone" width="110" /> -->
            <!-- <el-table-column label="接单限制" align="center" prop="receiveLimit" /> -->
            <!-- <el-table-column label="所属公司" align="center" prop="company" /> -->
            <!-- <el-table-column label="所属代理" align="center" prop="proxy" /> -->
            <!-- <el-table-column label="属性" align="center" prop="attribute" /> -->
            <el-table-column label="状态" align="center" prop="status" :formatter="statusFormat" width="80" />
            <el-table-column label="实付金额" align="center" prop="pay" show-overflow-tooltip  />
            <el-table-column label="抢单价" align="center" prop="receivePay" show-overflow-tooltip  />
            <el-table-column label="备注" align="center" prop="detail" show-overflow-tooltip />
            <el-table-column label="创建时间" align="center" prop="createTime" width="150">
              <template slot-scope="scope">
                <span>{{ parseTime(scope.row.createTime) }}</span>
              </template>
            </el-table-column>
            <!-- <el-table-column label="应付" align="center" prop="payable" /> -->
            <!-- <el-table-column label="实付" align="center" prop="pay" /> -->
            <!-- <el-table-column label="操作" align="center" width="150" class-name="small-padding fixed-width">
              <template slot-scope="scope">
                <div style="text-align:left;">
                  <el-button
                    size="mini"
                    type="text"
                    icon="el-icon-edit"
                    @click="handleShow(scope.row)"
                  >详情</el-button>
                  <el-button
                    size="mini"
                    type="text" v-if="scope.row.status != 0 && scope.row.status != 30"
                    icon="el-icon-search"
                    @click="openDistributeReceive(scope.row)"
                  >派单</el-button>
                  <el-button
                    size="mini"
                    type="text" v-if="scope.row.status >0 && scope.row.status < 15 "
                    icon="el-icon-circle-check"
                    @click="cancelOrder(scope.row)"
                  >取消</el-button>
                  <el-button
                    size="mini"
                    type="text" v-if="scope.row.status == 0"
                    icon="el-icon-delete"
                    @click="handleDelete(scope.row)"
                    v-hasPermi="['business:order:remove']"
                  >删除</el-button>
                </div>

              </template>
            </el-table-column> -->
          </el-table>

          <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize" @pagination="getList" />
        </el-card>
      </el-col>
    </el-row>


    <!-- 添加或修改订单管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="50%">
      <el-form ref="form" :model="form" :rules="rules" label-width="120px" :disabled="disabled">
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="服务信息" prop="attribute">
              <el-input v-model="form.attribute" placeholder="请选择服务" :readonly="true">
                <el-button slot="append" icon="el-icon-search" @click="openSelectAttribute"></el-button>
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="订单信息" prop="attribute">
              <el-input type="textarea" :rows="2" v-model="form.attribute" placeholder="请输入订单信息" />
            </el-form-item>
            <el-col :span="12">
              <el-form-item label="规格属性" prop="tags">
                <el-input v-model="form.tags" placeholder="规格属性" />
              </el-form-item>
            </el-col>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="预约时间" prop="orderTime">
              <el-date-picker clearable size="small" v-model="form.orderTime" type="datetime"
                value-format="yyyy-MM-dd HH:mm:ss" placeholder="选择预约时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">

          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="24">
            <el-form-item label="选择地址" prop="address">
              <el-input v-model="form.address" placeholder="请选择地址" :readonly="true">
                <el-button slot="append" icon="el-icon-search" @click="openSelectAddress"></el-button>
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="联系人" prop="username">
              <el-input v-model="form.username" placeholder="请输入联系人姓名" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="联系电话" prop="telephone">
              <el-input v-model="form.telephone" placeholder="请输入联系人电话" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="接单人" prop="receiveName">
              <el-input v-model="form.receiveName" placeholder="请选择接单人" :readonly="true">
                <el-button slot="append" icon="el-icon-search" @click="openSelectReceive"></el-button>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="接单电话" prop="receivePhone">
              <el-input v-model="form.receivePhone" placeholder="请输入接单人电话" :readonly="true" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="所属公司" prop="company">
              <el-input v-model="form.company" placeholder="请输入接单人所属公司" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="所属代理" prop="proxy">
              <el-input v-model="form.proxy" placeholder="请输入接单人所属代理" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="应付" prop="payable">
              <el-input v-model="form.payable" placeholder="请输入应付" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="实付" prop="pay">
              <el-input v-model="form.pay" placeholder="请输入实付" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="24">
            <el-form-item label="备注" prop="remark">
              <el-input type="textarea" :rows="2" v-model="form.remark" placeholder="请输入备注" />
            </el-form-item>
          </el-col>
          <el-col :span="12">

          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>

      <select-attribute ref="selectAttrForm" v-if="attrOpen" @finishSelected="finishSelectAttr"></select-attribute>
      <select-receive ref="selectReceiveForm" v-if="receiveOpen" @finishSelected="finishSelectReceive"></select-receive>
      <select-address ref="selectAddressForm" v-if="addressOpen" @finishSelected="finishSelectAddress"></select-address>

    </el-dialog>

    <distribute-receive ref="distributeReceiveForm" v-if="distributeOpen"
      @finishSelected="finishDistributeReceive"></distribute-receive>
    <finish-order ref="finishOrderForm" v-if="finishOpen" @finishSelected="finishOrderSelected"></finish-order>
    <show-order ref="showOrderForm" v-if="showOpen"></show-order>
  </div>
</template>

<script>
import { listOrder, getOrder, delOrder, addOrder, updateOrder, exportOrder, cancelOrder } from "@/api/business/order";
import SelectAttribute from './selectAttribute';
import SelectReceive from './selectReceive';
import SelectAddress from './selectAddress';
import DistributeReceive from './distributeReceive';
import FinishOrder from './finishOrder';
import ShowOrder from './showOrder';

import { treeListProxy } from "@/api/business/proxy";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";

export default {
  name: "Order",
  components: {
    SelectAttribute,
    SelectReceive,
    SelectAddress,
    DistributeReceive,
    FinishOrder,
    ShowOrder,
    Treeselect
  },
  watch: {
    filterText(val) {
      this.$refs.tree.filter(val);
    }
  },
  data() {

    return {
      filterText: '',
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      tabActiveName: 'all',
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 订单管理表格数据
      orderList: [],
      // 部门树选项
      proxyOptions: undefined,
      currentProxy: null,
      defaultProps: {
        children: "children",
        label: "name"
      },
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      disabled: false,
      attrOpen: false,
      receiveOpen: false,
      addressOpen: false,
      distributeOpen: false,
      finishOpen: false,
      showOpen: false,
      // 预约时间时间范围
      daterangeOrderTime: [],
      // 创建人名称时间范围
      daterangeCreateTime: [],
      // 状态数据字典
      statusOptions: [],
      payTypeOptions: [],
      resultOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        num: null,
        detail: null,
        orderTime: null,
        userId: null,
        username: null,
        telephone: null,
        receiveId: null,
        receiveName: null,
        receivePhone: null,
        receiveLimit: null,
        group: null,
        attribute: null,
        status: null,
        createName: null,
        createId: null,
        createTime: null,
        payable: null,
        pay: null,
        payMethod: null,
        shareUser: null,
        jingli: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        attribute: [
          { required: true, message: "服务信息不能为空", trigger: "blur" }
        ],
        orderTime: [
          { required: true, message: "预约时间不能为空", trigger: "blur" }
        ],
        detail: [
          { required: true, message: "订单信息不能为空", trigger: "blur" }
        ],
        username: [
          { required: true, message: "联系人不能为空", trigger: "blur" }
        ],
        telephone: [
          { required: true, message: "联系电话不能为空", trigger: "blur" }
        ],
        receiveName: [
          { required: true, message: "接单人不能为空", trigger: "blur" }
        ],
        receivePhone: [
          { required: true, message: "接单电话不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
    this.getTreeselect();
    this.getDicts("tb_order_status").then(response => {
      this.statusOptions = response.data;
    });
    this.getDicts("tb_payment_type").then(response => {
      this.payTypeOptions = response.data;
    });
    this.getDicts("tb_check_reason").then(response => {
      this.resultOptions = response.data;
    });
  },
  activated() {
    console.log("activated")
  },
  methods: {

    /** 查询订单管理列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeOrderTime && '' != this.daterangeOrderTime) {
        this.queryParams.params["beginOrderTime"] = this.daterangeOrderTime[0];
        this.queryParams.params["endOrderTime"] = this.daterangeOrderTime[1];
      }
      if (null != this.daterangeCreateTime && '' != this.daterangeCreateTime) {
        this.queryParams.params["beginCreateTime"] = this.daterangeCreateTime[0];
        this.queryParams.params["endCreateTime"] = this.daterangeCreateTime[1];
      }
      listOrder(this.queryParams).then(response => {
        this.orderList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    /** 查询部门下拉树结构 */
    getTreeselect() {
      treeListProxy().then(response => {
        this.proxyOptions = response.data;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        num: null,
        detail: null,
        orderTime: null,
        userId: null,
        username: null,
        telephone: null,
        receiveId: null,
        receiveName: null,
        receivePhone: null,
        receiveLimit: null,
        group: null,
        attribute: null,
        status: 0,
        remark: null,
        createName: null,
        createId: null,
        createTime: null,
        payable: null,
        pay: null,
        payMethod: null,
        address: null,
        addressId: null,
        orderAddress: {
          address: null
        }
      };
      this.resetForm("form");
    },
    // 筛选节点
    filterNode(value, data) {
      if (!value) return true;
      return data.name.indexOf(value) !== -1;
    },
    // 节点单击事件
    handleNodeClick(data) {
      this.queryParams.proxyId = data.id;
      this.currentProxy = data;
      this.getList();
    },
    // 字典状态字典翻译
    statusFormat(row, column) {

      return this.selectDictLabel(this.statusOptions, row.status);
    },
    // 字典状态字典翻译
    formatPaytype(row, column) {
      return this.selectDictLabel(this.payTypeOptions, row.payType);
    },
    // 字典状态字典翻译
    resultFomat(row, column) {
      return this.selectDictLabel(this.resultOptions, row.result);
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeOrderTime = [];
      this.daterangeCreateTime = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    handleTabClick(tab, event) {
      console.log(tab, event);
      if (tab.name != 'all') {
        this.queryParams.status = tab.name;
      } else {
        this.queryParams.status = '';
      }
      this.getList();
    },
    openSelectAttribute() {
      this.attrOpen = true;
      this.$nextTick(() => {
        this.$refs['selectAttrForm'].init();
      });

    },
    finishSelectAttr(data) {
      this.form.attribute = data.name;
      this.form.pay = data.price;
      this.form.payable = data.price;
    },
    openSelectReceive() {
      this.receiveOpen = true;
      this.$nextTick(() => {
        this.$refs['selectReceiveForm'].init();
      });
    },
    finishSelectReceive(data) {
      console.log(data)
      this.form.receiveId = data.userId;
      this.form.receiveName = data.nickName;
      this.form.receivePhone = data.phonenumber;
      //
      this.form.proxyId = data.proxyId;
      this.form.proxy = data.proxy?.name;
      this.form.companyId = data.companyId;
      this.form.company = data.company?.name;
    },
    openSelectAddress() {
      this.addressOpen = true;
      this.$nextTick(() => {
        this.$refs['selectAddressForm'].init();
      });
    },
    finishSelectAddress(data) {
      console.log(data)
      this.form.orderAddress = data;
      this.form.address = data.detail;
      this.form.addressId = data.id;
      //
      this.form.userId = data.userId;
      this.form.username = data.userName;
      this.form.telephone = data.userTelephone;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加订单";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getOrder(id).then(response => {
        this.form = response.data;
        this.form.address = response.data.orderAddress.detail;
        this.open = true;
        this.title = "订单管理";
      });
    },
    handleShow(row) {
      this.showOpen = true;
      this.$nextTick(() => {
        this.$refs['showOrderForm'].init(row);
      });
    },

    openDistributeReceive(row) {
      this.distributeOpen = true;
      this.$nextTick(() => {
        this.$refs['distributeReceiveForm'].init(row);
      });
    },
    finishDistributeReceive(data) {
      this.getList();
    },
    finishOrder(row) {
      this.finishOpen = true;
      this.$nextTick(() => {
        this.$refs['finishOrderForm'].init(row);
      });
    },
    finishOrderSelected(data) {
      debugger
      this.getList();
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateOrder(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            this.form.status = 10;//已接单
            addOrder(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除订单管理编号为"' + ids + '"的数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function () {
        return delOrder(ids);
      }).then(() => {
        this.getList();
        this.msgSuccess("删除成功");
      })
    },
    /** 删除按钮操作 */
    cancelOrder(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认取消订单编号为"' + ids + '"的数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function () {
        return cancelOrder(ids);
      }).then(() => {
        this.getList();
        this.msgSuccess("取消成功");
      })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有订单管理数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        this.exportLoading = true;
        return exportOrder(queryParams);
      }).then(response => {
        this.download(response.msg);
        this.exportLoading = false;
      })
    }
  }
};
</script>
<style>
.el-tree-node__content {
  margin-top: 10px;
}
</style>
